<extend name="Public/base"/>

<block name="style">
  <link rel="stylesheet" type="text/css" href="__CSS__/order.css" media="all">
</block>

<block name="body">
  <!-- 标题 -->
  <div class="main-title">
    <h2>商品列表({$_total})</h2>
  </div>

  <!-- 按钮工具栏 -->
  <div class="cf">
    <div class="fl">
      <div class="btn-group">
        <a class="btn item_add" href="{:U('Item/add')}">新 增</a>
      </div>
      <button class="btn ajax-post confirm" target-form="ids" url="{:U('Item/setStatus',array('status'=>-1))}">删 除</button>
      <button class="btn ajax-post" target-form="ids" url="{:U('Item/setStatus',array('status'=>1))}">上 架</button>
      <button class="btn ajax-post confirm" target-form="ids" url="{:U('Item/setStatus',array('status'=>0))}">下 架</button>
    </div>

    <!-- 高级搜索 -->
    <form id="J_search_form" action="{:U('index')}" method="GET">
      <div class="search-form fr cf">
        <div class="fl">
          <select name="status">
            <option value="-">全部状态</option>
            <option value="1">销售中</option>
            <option value="0">已下架</option>
            <option value="-2">违规下架</option>
          </select>
        </div>
        <div class="fl" id="J_itemCategory">
          <select name="cid_1">
            <option value="">全部分类</option>
            <volist name="cid_1" id="vo">
                <option value="{$vo.id}" <if condition="I('cid_1') eq $vo['id']">selected</if>>{$vo.name}</option>
            </volist>
          </select>
          <select name="cid_2">
            <option value="">请选择</option>
              <volist name="cid_2" id="vo">
                <option value="{$vo.id}" <if condition="I('cid_2') eq $vo['id']">selected</if>>{$vo.name}</option>
              </volist>
          </select>
          <select name="cid_3">
            <option value="">请选择</option>
              <volist name="cid_3" id="vo">
                <option value="{$vo.id}" <if condition="I('cid_3') eq $vo['id']">selected</if>>{$vo.name}</option>
              </volist>
          </select>
        </div>
        <div class="sleft">
          <input type="text" name="keywords" class="search-input" value="{:I('keywords')}" placeholder="请输入商品名称或者编号">
          <a class="sch-btn" href="javascript:;" id="J_search"><i class="btn-search"></i></a>
        </div>
      </div>
    </form>
  </div>
  
  <table class="order-table-head">
    <tr>
      <th width="30">
         <input class="checkbox check-all" type="checkbox">
      </th>
      <th width="365">商品基本信息</th>
      <th width="105" class="text-center"><a href="{:U('index?_field=price&_order='.$_order)}" title="按售价排序">售价{$_order_icon.price}{$_order_icon_show}</a></th>
      <php>if($user['member_id']=='1'&&$user['member_name']=='jipu'):</php>
      <th width="105" class="text-center"><a href="{:U('index?_field=gprice&_order='.$_order)}" title="按供应价排序">供应价{$_order_icon.gprice}{$_order_icon_show}</a></th>
      <th width="105" class="text-center"><a href="{:U('index?_field=zprice&_order='.$_order)}" title="按直播价排序">直播价{$_order_icon.zprice}{$_order_icon_show}</a></th>
      <th width="105" class="text-center"><a href="{:U('index?_field=ztrate&_order='.$_order)}" title="按直播员利润提成比率排序">直播员提成比率{$_order_icon.ztrate}{$_order_icon_show}</a></th>
      <th width="105" class="text-center"><a href="{:U('index?_field=zbyprice&_order='.$_order)}" title="按直播员单价排序">直播员单价{$_order_icon.zbyprice}{$_order_icon_show}</a></th>
      <php>endif</php>
      <th width="70" class="text-center"><a href="{:U('index?_field=sdp&_order='.$_order)}" title="按返现金额排序">返现{$_order_icon.sdp}{$_order_icon_show}</a></th>
      <th width="75"><a href="{:U('index?_field=stock&_order='.$_order)}" title="按库存排序">库存{$_order_icon.stock}{$_order_icon_show}</a></th>
      <th width="75">购买数</th>
      <th width="78"><a href="{:U('index?_field=credit&_order='.$_order)}" title="按送积分数量">送积分{$_order_icon.credit}{$_order_icon_show}</a></th>
      <th>&nbsp;</th>
      <th width="150" class="text-center">操作</th>
    </tr>
  </table>
  <notempty name="list">
  <volist name="list" key='key' id="vo">
      <table class="order-table status-<elt name='vo.status' value='0'>0<else/>1</elt> ">
        <tr>
          <th colspan="10">
            <span class="text-cancel">ID：</span>
            {$vo.id}
            <span class="split-tab"></span>
            <span class="text-cancel">商品编号：</span>
            <a href="{:U('/Item/detail?id='.$vo['id'])}" target="_blank" title="点击商品信息">{$vo.number}</a>
            <span class="split-tab"></span>
            <span class="text-cancel">分类：</span>
            {$vo.category}
          </th>
        </tr>
        <tr>
          <td width="20" class="text-center">
            <input name="ids[]" class="ids" type="checkbox" value="{$vo['id']}"> 
          </td>
          <td width="50" class="item-lists text-center">
            <a href="{:U('/Item/detail?id='.$vo['id'])}" target="_blank"><img src="{:get_image_thumb(get_cover($vo['images'], 'path'), 60, 60)}" title="{$vo.title}"></a>
          </td>
          <td width="285">
          <neq name="vo.status" value="-2">
            <a href="{:U('edit?id='.$vo['id'])}">{$vo['name']}</a>
          <else />
            {$vo['name']}
          </neq>
          </td>
          <td width="90" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="price" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改售价" class="text text-right input-mini J_ajax_updatefield" value="{$vo.price}">
            元
          </td>
          <php>if($_SESSION['jipushop_isadmin']):</php>
          <td width="90" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="gprice" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改供应链底价" class="text text-right input-mini J_ajax_updatefield" value="{$vo.gprice}">
            元
          </td>
          <td width="90" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="zprice" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改直播市场价" class="text text-right input-mini J_ajax_updatefield" value="{$vo.zprice}">
            元
          </td>
          <td width="90" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="ztrate" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改直播员提成比率" class="text text-right input-mini J_ajax_updatefield" value="{$vo.ztrate}">
            元
          </td>
          <td width="90" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="zbyprice" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改直播插员产品提成单价" class="text text-right input-mini J_ajax_updatefield" value="{$vo.zbyprice}">
            元
          </td>
          <php>endif</php>

          <td width="60" class="text-center">
            <input type="text" readonly data-action="{:U('Item/setFieldValue')}" name="sdp" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改返现金额" class="text text-right input-xmini J_ajax_updatefield" value="{$vo.sdp}">
            <if condition="$vo['sdp_type'] eq 1">%<else/>元</if>
          </td>
          <td width="60" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="stock" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改库存" class="text text-right input-xmini J_ajax_updatefield" value="{$vo.stock}">
            件
          </td>
          <td width="60" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="buynum" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}"  title="修改已售数量" class="text text-right input-xmini J_ajax_updatefield" value="{$vo.buynum}">
            件
          </td>
          <td width="68" class="text-center">
            <input type="text" data-action="{:U('Item/setFieldValue')}" name="credit" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" data-id="{$vo['id']}" title="修改赠送积分数" class="text text-right input-xmini J_ajax_updatefield" value="{$vo.credit}">
          </td>
          <td class="text-right">
            <if condition="$vo['is_seckill']">
              <i class="icon icon-miaosha" style="color:red"></i>
            </if>
            <neq name="vo.status" value="-2">
                <!-- <a href="{:U('ItemComment/index?item_id='.$vo['id'])}">[评价]</a> -->
                <a class="copyLink" href="{:U('edit?id='.$vo['id'])}">[复制链接]</a>
                <a href="{:U('edit?id='.$vo['id'])}">[编辑]</a>
                <a href="{:U('setStatus?ids='.$vo['id'].'&status='.abs(1-$vo['status']))}" class="ajax-get">[{$vo.status_text}]</a>
                <a href="{:U('setStatus?status=-1&ids='.$vo['id'])}" class="confirm ajax-get">[删除]</a>
            <else />
            [违规下架了]
            </neq>
            
          </td>
        </tr>
      </table>
  </volist>
  <else/>
    <div class="list-empty">
      暂无商品！
    </div>
  </notempty>
  
  <!-- 分页 -->
  <div class="page">
    {$_page}
  </div>
</block>

<block name="script">
  <script type="text/javascript">
    $(function(){
      //导航高亮
      highlight_subnav("{:U('Item/index')}");
      Core.setValue('status', '{:I("get.status")}');
      
      //隐藏没有分类的下拉框
      var hideCat = {
        init : function(){
          this.hide('cid_2');
          this.hide('cid_3');
        },
        hide : function(name){
          var obj = $("select[name='" + name + "']");
          if(obj.children('option').length === 1){
            obj.hide();
          }
        }
      };
      hideCat.init();
    });

    // 获取所有带有 copyLink 类的链接
    const copyLinkBtns = document.querySelectorAll('.copyLink');

    // 遍历每个链接，并为其添加点击事件监听器
    copyLinkBtns.forEach(link => {
      link.addEventListener('click', function(event) {
        event.preventDefault(); // 阻止默认的链接跳转行为
        // 获取当前链接的 data-href 属性值
        const linkHref = "https://shop.shante.me"+link.getAttribute('href');
        const textarea = document.createElement('textarea');
        textarea.value = linkHref;
        this.appendChild(textarea);
        textarea.focus();
        textarea.select();
        try {
          document.execCommand('copy');
          layer.tips('链接复制到剪贴板: ' +linkHref, this, { area: '500px', time: 2000 });
        } catch (err) {
          console.error('备用复制方法也失败:', err);
        } finally {
          textarea.remove();
        }
      });
    });
  </script>
</block>
